package com.idempotent.xgfidempotent.factory.impl;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.idempotent.xgfidempotent.factory.IdempotentInterface;
import com.idempotent.xgfidempotent.util.RedisTokenUtils;
@Component
public class StringIdempotentImpl  implements IdempotentInterface{
	
	@Autowired
	RedisTokenUtils redisToken;

	@Override
	public Boolean isFit(Object retVal) {
		return retVal instanceof String;
	}

	@Override
	public void execute(Object retVal) {
		getRequest().setAttribute("token", redisToken.getToken());
	}

	public HttpServletRequest getRequest() {
		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = attributes.getRequest();
		return request;
	}

}
